package com.droidlogic.mboxlauncher;

import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.TextView;
import java.lang.ref.SoftReference;
import java.util.List;

public class MyGridLayout extends GridLayout {
    private Context mContext;
    private Object mLock;

    public MyGridLayout(Context context) {
        super(context);
    }

    public MyGridLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        this.mLock = ((Launcher) this.mContext).getLock();
    }

    public MyGridLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    }

    public boolean onGenericMotionEvent(MotionEvent event) {
        if ((event.getSource() & 2) != 0) {
            switch (event.getAction()) {
                case 8:
                    ((Launcher) this.mContext).getHoverView().clear();
                    break;
            }
        }
        return super.onGenericMotionEvent(event);
    }

    /* access modifiers changed from: protected */
    public void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
    }

    public void setLayoutView(int mode, List<ArrayMap<String, Object>> list) {
        MyRelativeLayout view;
        synchronized (this.mLock) {
            if (getChildCount() > 0) {
                removeAllViews();
            }
            for (int i = 0; i < list.size(); i++) {
                if (mode == 0) {
                    view = (MyRelativeLayout) View.inflate(this.mContext, R.layout.homegrid_item, (ViewGroup) null);
                    view.setType(6);
                } else {
                    view = (MyRelativeLayout) View.inflate(this.mContext, R.layout.childgrid_item, (ViewGroup) null);
                    ((TextView) view.getChildAt(1)).setText((String) list.get(i).get("name"));
                    view.setType(7);
                    view.setNumber(i);
                }
                ImageView img_bg = (ImageView) view.getChildAt(0);
                img_bg.setBackgroundDrawable(new SoftReference<>(this.mContext.getResources().getDrawable(parseItemBackground(i, mode))).get());
                if (list.get(i).get("icon") instanceof Drawable) {
                    img_bg.setImageDrawable(new SoftReference<>((Drawable) list.get(i).get("icon")).get());
                    view.setIntent((Intent) list.get(i).get("intent"));
                } else {
                    img_bg.setImageDrawable(new SoftReference<>(this.mContext.getResources().getDrawable(R.drawable.item_img_add)).get());
                    img_bg.setContentDescription("img_add");
                    view.setAddButton(true);
                }
                addView(view);
            }
        }
    }

    private int parseItemBackground(int num, int mode) {
        if (mode == 0) {
            switch (num % 11) {
                case 0:
                    return R.drawable.item_child_6;
                case 1:
                    return R.drawable.item_child_1;
                case 2:
                    return R.drawable.item_child_2;
                case 3:
                    return R.drawable.item_child_3;
                case 4:
                    return R.drawable.item_child_4;
                case 5:
                    return R.drawable.item_child_5;
                case 6:
                    return R.drawable.item_child_6;
                case 7:
                    return R.drawable.item_child_3;
                case 8:
                    return R.drawable.item_child_4;
                case 9:
                    return R.drawable.item_child_1;
                case 10:
                    return R.drawable.item_child_2;
                default:
                    return R.drawable.item_child_1;
            }
        } else {
            switch (num % 18) {
                case 0:
                    return R.drawable.item_child_4;
                case 1:
                    return R.drawable.item_child_1;
                case 2:
                    return R.drawable.item_child_2;
                case 3:
                    return R.drawable.item_child_3;
                case 4:
                    return R.drawable.item_child_4;
                case 5:
                    return R.drawable.item_child_5;
                case 6:
                    return R.drawable.item_child_6;
                case 7:
                    return R.drawable.item_child_3;
                case 8:
                    return R.drawable.item_child_4;
                case 9:
                    return R.drawable.item_child_1;
                case 10:
                    return R.drawable.item_child_2;
                case 11:
                    return R.drawable.item_child_6;
                case 12:
                    return R.drawable.item_child_5;
                case 13:
                    return R.drawable.item_child_6;
                case 14:
                    return R.drawable.item_child_2;
                case 15:
                    return R.drawable.item_child_5;
                case 16:
                    return R.drawable.item_child_3;
                case 17:
                    return R.drawable.item_child_1;
                default:
                    return R.drawable.item_child_1;
            }
        }
    }
}